//
//  LLCartViewController.m
//  lrlzapp
//
//  Created by dl on 16/2/22.
//  Copyright © 2016年 lrlz. All rights reserved.
//

#import "LLCartViewController.h"
#import "LLCartViewModel.h"
#import "LLCartItemTableViewCell.h"

@interface LLCartViewController () <UITableViewDelegate, UITableViewDataSource, LLAddMinusViewDelegate>
@property(nonatomic, strong, readwrite) LLCartViewModel *viewModel;
@property(weak, nonatomic) IBOutlet UITableView *tableView;
@end

@implementation LLCartViewController
@dynamic viewModel;

- (void)viewDidLoad {
    [super viewDidLoad];

    self.tableView.backgroundColor = UI_COLOR_BG_LIGHT_GREY;
    self.tableView.sectionIndexColor = [UIColor darkGrayColor];
    self.tableView.sectionIndexBackgroundColor = [UIColor clearColor];
    self.tableView.sectionIndexMinimumDisplayRowCount = 20;
    [self.tableView setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]];

    [self.tableView registerNib:[UINib nibWithNibName:@"LLCartItemTableViewCell" bundle:nil]
         forCellReuseIdentifier:IDENTIFIER_TABLEVIEW_CELL_CART_ITEM];
}

- (void)bindViewModel {
    [super bindViewModel];
}

#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    LLCartItemTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:IDENTIFIER_TABLEVIEW_CELL_CART_ITEM
                                                                    forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleDefault;
    cell.separatorInset = UIEdgeInsetsZero;
    cell.addMinusView.delegate = self;

    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return SUIT_H(90);
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

#pragma mark 
#pragma mark LLAddMinusViewDelegate

- (BOOL)addMinusViewWillIncrease {
    return YES;
}

- (BOOL)addMinusViewWillDecrease {
    return YES;
}

@end
